﻿Imports System.Data
Imports System.Data.OleDb
Public Class cls_taco
    Dim _cnBd As OleDbConnection
    Dim _ds_test As New DataSet
    Dim _strRequete As String
    Dim _cmd As New OleDbCommand
    Dim _da As New OleDbDataAdapter(_cmd)
    Dim _cmdBuilder As OleDbCommandBuilder
    Dim _table As String
    Dim _source As String
    Sub connexion()
        Dim strconnexion As String
        strconnexion = "Provider=Microsoft.Jet.OLEDB.4.0;"
        strconnexion &= "User ID=Admin;Password=;"
        strconnexion &= "Data source=" & "..\taco.mdb"
        _cnBd = New OleDbConnection(strconnexion)
        _cnBd.Open()
    End Sub

    Public Sub update(ByVal tablename As String)
        Dim cbVehicules = New OleDbCommandBuilder(_da)
        'on met à jour la base de données et on rafraichit le listView
        _da.Update(_ds_test, tablename)
    End Sub



    Sub defDataset(ByVal requete As String, ByVal table As String)

        connexion()

        _table = table

        'Définition de la commande

        _strRequete = requete
        With _cmd
            .Connection = _cnBd
            .CommandType = CommandType.Text
            .CommandText = _strRequete
        End With

        'remplir le dataset
        _ds_test.Clear()

        _da = New OleDbDataAdapter(_cmd)

        _da.Fill(_ds_test, table)

        fermerConnexion()
    End Sub

    Sub defDataset(ByVal cmdReq As OleDbCommand, ByVal table As String)

        connexion()
        _table = table

        'Définition de la commande

        _cmd = cmdReq
        _cmd.Connection = _cnBd
        _cmd.CommandType = CommandType.Text

        'remplir le dataset
        _ds_test.Clear()

        _da = New OleDbDataAdapter(_cmd)

        _da.Fill(_ds_test, table)
        fermerConnexion()
    End Sub

    ReadOnly Property ds()
        Get
            Return _ds_test
        End Get

    End Property
    Sub fermerConnexion()
        _cnBd.Close()
    End Sub


End Class

